function HandlePageIePayMent(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  this._queue = 0;
  
  this._createElements();
};
HandlePageIePayMent.prototype._createElements = function() {
  var _self = this;
  this._popupBox = new PopupBox();
  this._search = DlmanageUtils.search();
  
  tr = this._gui.mains.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.backgroundColor = '#fff';
  td.colSpan = 8;
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._loadData();
};

HandlePageIePayMent.prototype._loadData = function() {
  this._results = null;
  this._dateZones = null;
  this._customers = null;
  this._parameters = null;
  this._retrieveResults(1);
  this._retrieveCustomers(1);
  this._retrieveDateZones();
};

HandlePageIePayMent.prototype._verifyData = function() {
  if (this._dateZones && this._customers && this._results && this._parameters) {
    this._updateElements();
  }
};

HandlePageIePayMent.prototype._retrieveResults = function(page, order, queue, condition, from, to, pfrom, pto) {
  var _self = this;
  var args = 'c=LEFT JOIN ' + DlmanageUtils.tableMyOrder + ' AS o ON o.customerId = c.e_oid WHERE ' + ((condition) ? condition : '1 = 1') + ((page) ? '&p=' + page : '') + ((from) ?  '&from=' + from : '') + ((to) ?  '&to=' + to : '') + ((pfrom) ?  '&pfrom=' + pfrom : '') + ((pto) ?  '&pto=' + pto : '')+('&opr='+_self._operator.type);
  
  new RequestUtils()._mysql('ieincomecustomerallpaid', args, function(result, params) { _self._results = result;
                                                                                    _self._verifyData.call(_self);
                                                                                  }, null);
};

HandlePageIePayMent.prototype._retrieveCustomers = function(page, order, queue, condition, from, to, pfrom, pto) {
  var _self = this;
  if (condition) {
    var tmp = condition.indexOf('WHERE');
    condition = condition.substr((tmp != -1) ? tmp + 6 : 0);
  }
  var args = 'c=  WHERE '  + ((condition) ? condition : '1 = 1') + '&s=20' + ((page) ? '&p=' + page : '') + ((order) ? '&o=' + order : '') + ((queue) ? '&q=' + queue : '') + ((from) ?  '&from=' + from : '') + ((to) ?  '&to=' + to : '') + ((pfrom) ?  '&pfrom=' + pfrom : '') + ((pto) ?  '&pto=' + pto : '')+('&opr='+_self._operator.type);
  new RequestUtils()._mysql('customerpayments', args, function(result, params) { _self._customers = result.data;
                                                                          _self._parameters = result;
                                                                          _self._verifyData.call(_self);
                                                                        }, null);
};

HandlePageIePayMent.prototype._retrieveDateZones = function(page, condition, date, from, to, pos) {
  var _self = this;
   var arg ="&c=d.page=\'" + this._options.template + "\' ";
  /*new RequestUtils()._read('datezone', null, 'd.page=\'' + this._options.template + '\'', null, null, null, null, function(result, params) { _self._dateZones = result.data;
                                                                                                                                             _self._verifyData.call(_self);
                                                                                                                                           }, null);*/
  new RequestUtils()._mysql('datezone', arg, function(result, params) { _self._dateZones = result.data;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php',pos: (pos) ? pos : null });                                                                                                                                           
};

HandlePageIePayMent.prototype._updateElements = function() {
  var _self = this;
  DlmanageUtils.clear(this._gui.summarize);
  DOMUtils.removeTableRows(this._gui.mains, 1);
  DlmanageUtils.clear(this._gui.dateZone);
  DOMUtils.removeChildElements(this._gui.pagination);

  /*------SUMMARIZE------*/
  this._gui.summarize.cNo.appendChild(document.createTextNode(this._results.customer));
  this._gui.summarize.totalRevenue.appendChild(document.createTextNode('$' + parseFloat(this._results.tolRev, 10).toFixed(2)));
  this._gui.summarize.receipt.appendChild(document.createTextNode('$' + parseFloat(this._results.receipt, 10).toFixed(2)));
  this._gui.summarize.anticipated.appendChild(document.createTextNode('$' + parseFloat(this._results.anticipated, 10).toFixed(2)));
  this._gui.summarize.cash.appendChild(document.createTextNode('$' + parseFloat(this._results.cash, 10).toFixed(2)));
  this._gui.summarize.nonCash.appendChild(document.createTextNode('$' + parseFloat(this._results.noncash, 10).toFixed(2)));
  this._gui.summarize.nonPayment.appendChild(document.createTextNode(this._results.noPayment));
  this._gui.summarize.revenue.appendChild(document.createTextNode('$' + parseFloat(this._results.revenue, 10).toFixed(2)));
  var span = document.createElement('span');
  span.style.color = '#663333';
  span.style.fontSize = '12px';
  span.appendChild(document.createTextNode(((this._results.tolRev == 0) ? '' : ' (' + (((this._results.revenue) / (this._results.tolRev)) * 100).toFixed(1) + '%) ')));
  this._gui.summarize.revenue.appendChild(span);
  this._gui.summarize.netRevenue.appendChild(document.createTextNode('$' + (this._results.netrev).toFixed(2)));
  /*-----SORT-----*/
  //this._queue = !this._queue;
  //this._gui.date.onclick = function() { _self._retrieveCustomers.call(_self, _self._parameters.page, 'c.createdDate', (_self._queue) ? 'ASC' : 'DESC', _self._parameters.condition); };
 // this._gui.customer.onclick = function() { _self._retrieveCustomers.call(_self, _self._parameters.page, 'c.e_oid', (_self._queue) ? 'ASC' : 'DESC', _self._parameters.condition); };
  //this._gui.sort.onclick = function() { };
  
  /*-----MAIN TABLE-----*/
  if (this._customers.length == 0) {
    tr = this._gui.mains.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 8;
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('N/A'));
  }
  for (var i = 0, il = this._customers.length; i < il; i++) {
    var customer = this._customers[i];
    //for (var j = 0, jl = customer.orders.length; j < jl; j++) {
     // var order = customer.orders[j];
     // if (order.disposal.status) {
     //   continue;
     // }
     // var cash = 0, noncash = 0, receipt = 0;
      /*for (k = 0, kl = order.payments.length; k < kl; k++) {
        var payment = order.payments[k];
        if (payment.cancelled == 1) {
          continue;
        }
        receipt += parseFloat(payment.amount, 10);
        if (payment.method == 'cash') {
          cash += parseFloat(payment.amount, 10);
        } else {
          noncash += parseFloat(payment.amount, 10);
        }
      }*/
      
      tr = this._gui.mains.insertRow(-1);
      td = tr.insertCell(-1);
      td.className = 'elemsumcustomerall_td15';
      td.appendChild(document.createTextNode(SimpleDate.format(customer.pdate)));
      
      td = tr.insertCell(-1);
      td.appendChild(document.createTextNode(DlmanageUtils.customerId(customer.e_oid)));
      
      td = tr.insertCell(-1);
      td.appendChild(document.createTextNode(customer.orderflag));
      
      td = tr.insertCell(-1);
      td.className = 'elemsumcustomerall_td14';
      td.appendChild(document.createTextNode('$' + customer.total));

      td = tr.insertCell(-1);
      td.className = 'elemsumcustomerall_td15';
      td.appendChild(document.createTextNode('$' + parseFloat(customer.cash, 10).toFixed(2)));
      
      td = tr.insertCell(-1);
      td.className = 'elemsumcustomerall_td16';
      td.appendChild(document.createTextNode('$' + parseFloat(customer.nocash, 10).toFixed(2)));
      
      td = tr.insertCell(-1);
      td.appendChild(document.createTextNode('$' + parseFloat(customer.total - customer.ptotal, 10).toFixed(2)));
      
      td = tr.insertCell(-1);
      td.style.height = '24px';
      td.appendChild(document.createTextNode(SimpleDate.format(customer.ccdate)));      
    //}
  }

  /*--DATE ZONE----*/
  this._dateZone = { created: '',
                     to: ''
                   };
  this._gui.dateZone.dateCreated.value = (this._dateZone.created) ? SimpleDate.format(this._dateZone.created) : '';
  this._gui.dateZone.dateCreated.onclick = function() { var context = this;
                                                        _self._changeDate.call(_self, this, _self._dateZone.created, function(sd) { _self._dateZone.created = sd; context.focus(); }, false);
                                                        return false;
                                                      };
  this._gui.dateZone.dateTo.value = (this._dateZone.to) ? SimpleDate.format(this._dateZone.to) : '';
  this._gui.dateZone.dateTo.onclick = function() { var context = this;
                                                   _self._changeDate.call(_self, this, _self._dateZone.to, function(sd) { _self._dateZone.to = sd; context.focus(); }, false);
                                                   return false;
                                                 };
  this._gui.dateZone.create.onclick = function() { if (_self._dateZone.created &&_self._dateZone.to) {
                                                     var date = DateZone.instance();
                                                     date.start = _self._dateZone.created;
                                                     date.end = _self._dateZone.to;
                                                     date.page = _self._options.template;
                                                     new RequestUtils()._mwrite('datezone', [date], [], function(date, params) { _self._retrieveDateZones.call(_self);}, DOMUtils.findPos(this));
                                                   } else {
                                                     window.alert('DATE CAN NOT BE EMPTY');
                                                   }
                                                 };
  var table = document.createElement('table');
  table.style.width = '166px';
  table.cellPadding = 0;
  table.cellSpacing = 0;
  this._gui.dateZone.result.appendChild(table);
  for (var i = 0, il = this._dateZones.length; i < il; i++) {
    var date = this._dateZones[i];
    tr = table.insertRow(-1);
    tr.className = (tr.rowIndex % 2 == 0) ? 'rowodd' : 'roweven';
    td = tr.insertCell(-1);
    td.style.width = '146px';
    td.style.height = '20px';
    td.style.textAlign = 'center';
    var a = document.createElement('a');
    a.href = '#';
    a._date = date;
    a.appendChild(document.createTextNode(SimpleDate.format(date.start) + ' - ' + SimpleDate.format(date.end)));
    a.onclick = function() { _self._search.dateFrom = this._date.start;
                             _self._search.dateTo = this._date.end;
                             _self._retrieveResults.call(_self, 1, null, null, '1=1', JSON.stringify(this._date.start), JSON.stringify(this._date.end)); 
                             _self._retrieveCustomers.call(_self, 1, null, null, '1=1', JSON.stringify(this._date.start), JSON.stringify(this._date.end)); 
                             return false;
                           };
    td.appendChild(a);
    td = tr.insertCell(-1);
    td.style.width = '20px';
    td.style.textAlign = 'center';
    var span = document.createElement('span');
    span.appendChild(document.createTextNode('(x)'));
    span.style.cursor = 'pointer';
    span._date = date;
    span.onclick = function() { 
                                new RequestUtils()._mwrite('datezone', [], [this._date], function(date, params) { _self._retrieveDateZones.call(_self);}, null);
                              };
    td.appendChild(span);
  }
  /*--PAGINATION--*/
  Pagination.makePagedResults(this._gui.pagination, this._parameters.page, this._parameters.total, this._parameters.size, function(page, condition) { _self._retrieveCustomers.call(_self, page, _self._parameters.order, _self._parameters.queue, _self._parameters.condition); }, this, document);
  /*----SEARCH-----*/
  
  this._customerSearch(this._gui, function(order, queue, condition, from, to, pfrom, pto) { _self._retrieveResults.call(_self, 1, order, queue, condition, from, to, pfrom, pto); _self._retrieveCustomers.call(_self, 1, order, queue, condition, from, to, pfrom, pto); });
};

HandlePageIePayMent.prototype._customerSearch = function(gui, callbackFunc) {
  var _self = this;
  this._callbackFunc = callbackFunc;
  
  this._search.id = gui.search.cNo.value;
  gui.search.cNo.value = this._search.id;
  gui.search.cNo.onchange = function() { _self._search.id = this.value; };
  gui.search.cNo.onkeydown = function() { _self._search.id = this.value; };
  gui.search.cNo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                            if (code == 13) {
                                              _self._callbackFunc.call(_self, null, null, _self._toString(_self._search), (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null);
                                            }
                                          };
  gui.search.cNo.onkeyup = function() { if (gui.search.cNo.value.length == 0) {
                                          _self._popupBox._close();
                                        } else {
                                          var div = document.createElement('div');
                                          var pos1 = DOMUtils.findPos(gui.search.cNo);
                                          var pos = [pos1[0] + 1, pos1[1] + 82];
                                          var query = "SELECT c.e_oid as id FROM  " +DlmanageUtils.tableCustomer + " as c WHERE 1 = 1 AND " + '((c.e_oid LIKE \'%' + gui.search.cNo.value + '%\'))' + " ";
                                          MiscUtils.dialog(_self._popupBox, pos, div, null, null, {pop: true});
                                          new DialogSearchResult(div, gui.search.cNo, { query: query, popupBox: _self._popupBox, callbackFunc: function() { _self._updateElements();}, width: 150});
                                        }
                                      };
//  gui.search.dateCreated.value = (this._search.dateFrom) ? SimpleDate.format(this._search.dateFrom) : '';
//  gui.search.dateCreated.onclick = function() { var context = this;
//                                                _self._changeDate.call(_self, this, _self._search.dateFrom, function(sd) { _self._search.dateFrom = sd; context.focus(); }, false);
//                                                return false;
//                                              };
//  gui.search.dateCreated.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
//                                                    if (code == 13) {
//                                                      _self._callbackFunc.call(_self, null, null, _self._toString(_self._search), (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null);
//                                                    }
//                                                  };
//  gui.search.dateTo.value = (this._search.dateTo) ? SimpleDate.format(this._search.dateTo) : '';
//  gui.search.dateTo.onclick = function() { var context = this;
 //                                          _self._changeDate.call(_self, this, _self._search.dateTo, function(sd) { _self._search.dateTo = sd; context.focus(); }, false);
//                                           return false;
//                                         };
//  gui.search.dateTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
//                                               if (code == 13) {
//                                                 _self._callbackFunc.call(_self, null, null, _self._toString(_self._search), (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null);
//                                               }
//                                             };
                                             
    if(this._operator.type=='{{$smarty.const.USER_TYPE_MANAGER_ASSISTANT|escape:javascrpit}}' || this._operator.type=='{{$smarty.const.USER_TYPE_MANAGER|escape:javascrpit}}')
  {                                     
                                      if(SimpleDate.toStamp(this._search.datepFrom) < (SimpleDate.toStamp(this._now) - 7776000) )
                                      {
                                          gui.search.datepaid.value =  SimpleDate.format(SimpleDate.fromStamp(SimpleDate.toStamp(this._now) - 7776000));
                                         
                                      }else{
                                        gui.search.datepaid.value = (this._search.datepFrom) ? SimpleDate.format(this._search.datepFrom) : SimpleDate.format(SimpleDate.fromStamp(SimpleDate.toStamp(this._now) - 7776000));
                                      }
     }else{                                 
      gui.search.datepaid.value = (this._search.datepFrom) ? SimpleDate.format(this._search.datepFrom) : '';
  }
                                               
  //gui.search.datepaid.value = (this._search.datepFrom) ? SimpleDate.format(this._search.datepFrom) : '';
  gui.search.datepaid.onclick = function() { var context = this;
                                                _self._changeDate.call(_self, this, _self._search.datepFrom, function(sd) { _self._search.datepFrom = sd; context.focus(); }, false);
                                                return false;
                                              };
  gui.search.datepaid.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                    if (code == 13) {
                                                      _self._callbackFunc.call(_self, null, null,null, null, _self._toString(_self._search), (_self._search.datepFrom) ? JSON.stringify(_self._search.datepFrom) : null, (_self._search.datepTo) ? JSON.stringify(_self._search.datepTo) : null);
                                                    }
                                                  };
  gui.search.datepTo.value = (this._search.datepTo) ? SimpleDate.format(this._search.datepTo) : '';
  gui.search.datepTo.onclick = function() { var context = this;
                                           _self._changeDate.call(_self, this, _self._search.datepTo, function(sd) { _self._search.datepTo = sd; context.focus(); }, false);
                                           return false;
                                         };
  gui.search.datepTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                               if (code == 13) {
                                                 _self._callbackFunc.call(_self, null, null,null, null, _self._toString(_self._search), (_self._search.datepFrom) ? JSON.stringify(_self._search.datepFrom) : null, (_self._search.datepTo) ? JSON.stringify(_self._search.datepTo) : null);
                                               }
                                             };                                             
                                             
 gui.search.search.onclick = function() { _self._callbackFunc.call(_self, null, null, _self._toString(_self._search), (_self._search.dateFrom) ? JSON.stringify(_self._search.dateFrom) : null, (_self._search.dateTo) ? JSON.stringify(_self._search.dateTo) : null, (_self._search.datepFrom) ? JSON.stringify(_self._search.datepFrom) : null, (_self._search.datepTo) ? JSON.stringify(_self._search.datepTo) : null); };
};

HandlePageIePayMent.prototype._toString = function(search) {
  var str = '';
  str += (search.id == '') ? '1 = 1' : ((isNaN(search.id)) ? '1 = 0' : '(c.e_oid = \'' + search.id + '\')');
  return escape(str);
};

HandlePageIePayMent.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandlePageIePayMent.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandlePageIePayMent.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};